package com.yiwenup.leetcode.hot;

import com.yiwenup.leetcode.TreeNode;

/**
 * @PROJECT struct-algorithm
 * @PACKAGE com.yiwenup.leetcode.hot
 * @Author yiwenup
 * @Date 2022-02-28 10:26:39
 * <p>
 * @DESCRIPTION https://leetcode-cn.com/problems/maximum-depth-of-binary-tree/
 */
public class No0104 {

    /**
     * 执行用时：0 ms, 在所有 Java 提交中击败了100.00%的用户
     * 内存消耗：40.8 MB, 在所有 Java 提交中击败了33.57%的用户
     */
    public int maxDepth(TreeNode root) {
        if (root == null) return 0;

        int leftDepth = maxDepth(root.left);
        int rightDepth = maxDepth(root.right);

        return Math.max(leftDepth, rightDepth) + 1;
    }
}
